package com.jia.yygh.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jia.yygh.hosp.mapper.HospitalSetMapper;
import com.jia.yygh.hosp.service.HospitalSetService;
import com.jia.yygh.model.hosp.HospitalSet;
import com.jia.yygh.vo.hosp.HospitalSetQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {

    @Override
    public Map<String, Object> queryPage(long pageNum, long pageSize, HospitalSetQueryVo hospitalSetQueryVo) {

        Page<HospitalSet> page = new Page<>(pageNum,pageSize);
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();

        wrapper.orderByDesc("create_time");

        if(!StringUtils.isEmpty(hospitalSetQueryVo.getHosname())){
            wrapper.like("hosname",hospitalSetQueryVo.getHosname());
        }
        if(!StringUtils.isEmpty(hospitalSetQueryVo.getHoscode())){
            wrapper.eq("hoscode",hospitalSetQueryVo.getHoscode());
        }

        Page<HospitalSet> hospitalSetPage = baseMapper.selectPage(page, wrapper);
        List<HospitalSet> records = hospitalSetPage.getRecords();
        long total = hospitalSetPage.getTotal();
        Map<String, Object> map = new HashMap<>();
        map.put("records",records);
        map.put("total",total);
        return map;

    }
}
